
import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
//导入组件
import Login from '../components/Login.vue'
import Register from '../components/Register.vue'
import Home from '../views/Home.vue'
import Category from '../views/Category.vue'
import Message from '../views/Message.vue'
import User from '../views/User.vue'
import GoodsInfo from '../views/GoodsInfo.vue'
import NewsList from '../components/NewsList'
var router = new VueRouter({
  mode: 'history',
  linkActiveClass: 'my-active',
  linkExactActiveClass: 'my-exact-active',
  routes: [
    { path: '/', redirect: '/home', name: 'home', meta: { title: '首页' } },
    { path: '/home', component: Home, meta: { title: '首页' } },
    { path: '/message', component: Message, name: 'message', meta: { title: '留言' } },
    { path: '/category', component: Category, name: 'category', meta: { title: '分类' } },
    { path: '/category/goodsInfo', component: GoodsInfo, name: 'goodsInfo', meta: { title: '商品详情' } },
    { path: '/user', component: User, name: 'user', meta: { title: '我的' } },
    { path: '/user/login', component: Login, meta: { title: '登录' } },
    { path: '/user/register', component: Register, meta: { title: '注册' } },
    {path:"/newsList",component:NewsList,name:'newsList',meta:{title:"新闻资讯"}}
  ]
})

//导航钩子函数
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()

})

export default router
